home *** CD-ROM | disk | FTP | other *** search
/ Aminet 31 / Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso / Aminet / dev / gui / gtlayout.lha / Source / LTP_Storage.c < prev    next >
C/C++ Source or Header  |  1998-09-09  |  5KB  |  325 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1998 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. #include "Assert.h"
  15.  
  16. VOID
  17. LTP_GetStorage(ObjectNode *Node)
  18. {
  19.     if(Node->Storage)
  20.     {
  21.         LONG    Number = 0;
  22.         STRPTR    String = NULL;
  23.  
  24.         switch(Node->StorageType)
  25.         {
  26.             case STORAGE_BYTE:
  27.  
  28.                 Number = *(BYTE *)Node->Storage;
  29.                 break;
  30.  
  31.             case STORAGE_UBYTE:
  32.  
  33.                 Number = *(UBYTE *)Node->Storage;
  34.                 break;
  35.  
  36.             case STORAGE_WORD:
  37.  
  38.                 Number = *(WORD *)Node->Storage;
  39.                 break;
  40.  
  41.             case STORAGE_UWORD:
  42.  
  43.                 Number = *(UWORD *)Node->Storage;
  44.                 break;
  45.  
  46.             case STORAGE_LONG:
  47.  
  48.                 Number = *(LONG *)Node->Storage;
  49.                 break;
  50.  
  51.             case STORAGE_ULONG:
  52.  
  53.                 Number = *(ULONG *)Node->Storage;
  54.                 break;
  55.  
  56.             case STORAGE_STRPTR:
  57.  
  58.                 String = Node->Storage;
  59.                 break;
  60.         }
  61.  
  62.         switch(Node->Type)
  63.         {
  64. #ifdef DO_POPUP_KIND
  65.             case POPUP_KIND:
  66. #endif    /* DO_POPUP_KIND */
  67. #ifdef DO_TAB_KIND
  68.             case TAB_KIND:
  69. #endif    /* DO_TAB_KIND */
  70. #ifdef DO_GAUGE_KIND
  71.             case GAUGE_KIND:
  72. #endif    /* DO_GAUGE_KIND */
  73. #ifdef DO_TAPEDECK_KIND
  74.             case TAPEDECK_KIND:
  75. #endif    /* DO_TAPEDECK_KIND */
  76. #ifdef DO_LEVEL_KIND
  77.             case LEVEL_KIND:
  78. #endif    /* DO_LEVEL_KIND */
  79.  
  80.             case CHECKBOX_KIND:
  81.             case LISTVIEW_KIND:
  82.             case MX_KIND:
  83.             case CYCLE_KIND:
  84.             case PALETTE_KIND:
  85.             case SLIDER_KIND:
  86.             case SCROLLER_KIND:
  87.  
  88.                 Node->Current = Number;
  89.                 break;
  90.  
  91. #ifdef DO_PASSWORD_KIND
  92.             case PASSWORD_KIND:
  93. #endif    /* DO_PASSWORD_KIND */
  94.  
  95.             case STRING_KIND:
  96.             case FRACTION_KIND:
  97.  
  98.                 Node->Special.String.String = String;
  99.                 break;
  100.  
  101.             case INTEGER_KIND:
  102.  
  103.                 Node->Special.Integer.Number = Number;
  104.                 break;
  105.         }
  106.     }
  107. }
  108.  
  109.  
  110. /*****************************************************************************/
  111.  
  112.  
  113. VOID
  114. LTP_PutStorage(ObjectNode *Node)
  115. {
  116.     if(Node->Storage)
  117.     {
  118.         LONG    Number = 0;
  119.         STRPTR    String = NULL;
  120.  
  121.         switch(Node->Type)
  122.         {
  123. #ifdef DO_POPUP_KIND
  124.             case POPUP_KIND:
  125. #endif    /* DO_POPUP_KIND */
  126. #ifdef DO_TAB_KIND
  127.             case TAB_KIND:
  128. #endif    /* DO_TAB_KIND */
  129. #ifdef DO_GAUGE_KIND
  130.             case GAUGE_KIND:
  131. #endif    /* DO_GAUGE_KIND */
  132. #ifdef DO_TAPEDECK_KIND
  133.             case TAPEDECK_KIND:
  134. #endif    /* DO_TAPEDECK_KIND */
  135. #ifdef DO_LEVEL_KIND
  136.             case LEVEL_KIND:
  137. #endif    /* DO_LEVEL_KIND */
  138.  
  139.             case CHECKBOX_KIND:
  140.             case LISTVIEW_KIND:
  141.             case MX_KIND:
  142.             case CYCLE_KIND:
  143.             case PALETTE_KIND:
  144.             case SLIDER_KIND:
  145.             case SCROLLER_KIND:
  146.  
  147.                 Number = Node->Current;
  148.                 break;
  149.  
  150.             #ifdef DO_PASSWORD_KIND
  151.             {
  152.                 case PASSWORD_KIND:
  153.  
  154.                     String = Node->Special.String.RealString;
  155.                     break;
  156.             }
  157.             #endif
  158.  
  159.             case STRING_KIND:
  160.             case FRACTION_KIND:
  161.  
  162.                 if(Node->Host)
  163.                     String = ((struct StringInfo *)Node->Host->SpecialInfo)->Buffer;
  164.                 else
  165.                     String = Node->Special.String.String;
  166.  
  167.                 if(Node->Type == FRACTION_KIND)
  168.                 {
  169.                     LTP_CopyFraction(Node->Special.String.RealString,String);
  170.                     String = Node->Special.String.RealString;
  171.                 }
  172.  
  173.                 break;
  174.  
  175.             case INTEGER_KIND:
  176.  
  177.                 if(Node->Host)
  178.                     Number = ((struct StringInfo *)Node->Host->SpecialInfo)->LongInt;
  179.                 else
  180.                     Number = Node->Special.Integer.Number;
  181.  
  182.                 break;
  183.         }
  184.  
  185.         switch(Node->StorageType)
  186.         {
  187.             case STORAGE_BYTE:
  188.  
  189.                 if(!String)
  190.                     *(BYTE *)Node->Storage = (BYTE)Number;
  191.  
  192.                 break;
  193.  
  194.             case STORAGE_UBYTE:
  195.  
  196.                 if(!String)
  197.                     *(UBYTE *)Node->Storage = (UBYTE)Number;
  198.  
  199.                 break;
  200.  
  201.             case STORAGE_WORD:
  202.  
  203.                 if(!String)
  204.                     *(WORD *)Node->Storage = (WORD)Number;
  205.  
  206.                 break;
  207.  
  208.             case STORAGE_UWORD:
  209.  
  210.                 if(!String)
  211.                     *(UWORD *)Node->Storage = (UWORD)Number;
  212.  
  213.                 break;
  214.  
  215.             case STORAGE_LONG:
  216.  
  217.                 if(!String)
  218.                     *(LONG *)Node->Storage = (LONG)Number;
  219.  
  220.                 break;
  221.  
  222.             case STORAGE_ULONG:
  223.  
  224.                 if(!String)
  225.                     *(ULONG *)Node->Storage = (ULONG)Number;
  226.  
  227.                 break;
  228.  
  229.             case STORAGE_STRPTR:
  230.  
  231.                 if(String)
  232.                     strcpy(Node->Storage,String);
  233.  
  234.                 break;
  235.         }
  236.     }
  237. }
  238.  
  239.  
  240. /*****************************************************************************/
  241.  
  242.  
  243. VOID
  244. LTP_CopyFraction(STRPTR To,STRPTR From)
  245. {
  246.     UBYTE DecimalPoint,c;
  247.     BOOL GotPoint;
  248.     STRPTR Orig;
  249.  
  250.         /* If there is nothing to copy from, pretend it's an empty string. */
  251.  
  252.     if(From == NULL)
  253.         From = "";
  254.  
  255.     DecimalPoint = LTP_DecimalPoint[0];
  256.  
  257.         /* Skip leading junk. */
  258.  
  259.     while(*From != '.' && (*From < '0' || *From > '9') && *From != '\0' && *From != DecimalPoint)
  260.         From++;
  261.  
  262.         /* Skip extraenous zeroes. */
  263.  
  264.     while(From[0] == '0')
  265.         From++;
  266.  
  267.     Orig = To;
  268.  
  269.         /* If the first character is just a decimal point, add a zero
  270.          * in front of it.
  271.          */
  272.  
  273.     if(*From == '.' || *From == DecimalPoint)
  274.         *To++ = '0';
  275.  
  276.     GotPoint = FALSE;
  277.  
  278.         /* Now copy and convert the number. */
  279.  
  280.     while(c = *From++)
  281.     {
  282.         if(c == DecimalPoint || c == '.')
  283.         {
  284.             if(!GotPoint)
  285.             {
  286.                 *To++ = '.';
  287.  
  288.                 GotPoint = TRUE;
  289.             }
  290.         }
  291.         else
  292.         {
  293.             if(c >= '0' && c <= '9')
  294.                 *To++ = c;
  295.         }
  296.     }
  297.  
  298.         /* If the string would remain blank,
  299.          * use a zero.
  300.          */
  301.  
  302.     if(Orig == To)
  303.         *To++ = '0';
  304.  
  305.         /* If we didn't get a decimal point, add one. */
  306.  
  307.     if(!GotPoint)
  308.     {
  309.         *To++ = '.';
  310.         *To++ = '0';
  311.     }
  312.  
  313.         /* Strip trailing zeroes if they follow the decimal point. */
  314.  
  315.     if(GotPoint)
  316.     {
  317.         while(To > Orig && To[-1] == '0' && To[-2] == '0')
  318.             To--;
  319.     }
  320.  
  321.         /* Terminate the string. */
  322.  
  323.     *To = '\0';
  324. }
  325.